package com.zhuhjay.eduservice.controller;


import com.zhuhjay.commonutils.R;
import com.zhuhjay.eduservice.entity.EduChapter;
import com.zhuhjay.eduservice.service.EduChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author ZhuHJay
 * @since 2022-09-06
 */
@Api(description = "章节控制器")
@RestController
@RequestMapping("/eduservice/chapter")

public class EduChapterController {

    @Resource
    private EduChapterService chapterService;

    @ApiOperation(value = "课程大纲列表，根据课程ID查询到章节及小节")
    @GetMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable String courseId) {
        return R.ok().data("allChapterVideo", chapterService.getChapterVideoByCourseId(courseId));
    }

    @ApiOperation(value = "添加章节信息")
    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter chapter) {
        chapterService.save(chapter);
        return R.ok();
    }

    @ApiOperation(value = "根据章节ID获取章节信息")
    @GetMapping("getChapterInfo/{chapterId}")
    public R getChapterInfo(@PathVariable String chapterId) {
        return R.ok().data("chapter", chapterService.getById(chapterId));
    }

    @ApiOperation(value = "更新修改章节信息")
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter chapter) {
        chapterService.updateById(chapter);
        return R.ok();
    }

    @ApiOperation(value = "根据章节ID删除章节信息")
    @DeleteMapping("{chapterId}")
    public R deleteChapter(@PathVariable String chapterId) {
        chapterService.removeIfNotVideo(chapterId);
        return R.ok();
    }

}

